package com.usefullc.demo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.demo.domain.Test1;
import com.usefullc.demo.mapper.Test1Mapper;
import com.usefullc.demo.query.Test1Query;
import com.usefullc.demo.vo.Test1Vo;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.service.AbstractBizService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 测试1服务类
 * @author: 星空
 * @date: 20220622
 */
@Service
public class Test1Service extends AbstractBizService<Test1Mapper, Test1, Test1Query> {


    @Override
    protected QueryWrapper<Test1> getQueryWrapper(Test1Query query) {
        QueryWrapper<Test1> queryWrapper = super.getQueryWrapper(query);

//        queryWrapper.apply(StringUtils.isNotBlank(query.getGmtCreateStart()),
//                "date_format (gmtCreate,'%Y-%m-%d') >= date_format('" + query.getGmtCreateStart() + "','%Y-%m-%d')")
//                .apply(StringUtils.isNotBlank(query.getGmtCreateEnd()),
//                        "date_format (gmtCreate,'%Y-%m-%d') <= date_format('" + query.getGmtCreateEnd() + "','%Y-%m-%d')");

        return queryWrapper;
    }

    public Pager<Test1Vo> findVoByPage(Test1Query query){
        Pager<Test1> page = this.findByPage(query);
        Pager<Test1Vo> newPage = new Pager<>(page);
        List<Test1> dataList = page.getDataList();
        List<Test1Vo> newDataList = new ArrayList<>();
        newPage.setDataList(newDataList);
        for (Test1 test1 : dataList) {
            Test1Vo test1Vo = BeanUtils.beanCopy(test1, Test1Vo.class);
            newDataList.add(test1Vo);
        }
        return newPage;
    }


}
